package io.renren.modules.nuaa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.constant.Constant;
import io.renren.modules.nuaa.dao.TUserDao;
import io.renren.modules.nuaa.dto.TUserDTO;
import io.renren.modules.nuaa.entity.TUserEntity;
import io.renren.modules.nuaa.service.TUserService;
import io.renren.modules.security.user.SecurityUser;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 前台用户表
 *
 * @author whc 15953295779@126.com
 * @since 3.0 2023-10-31
 */
@Service
public class TUserServiceImpl extends CrudServiceImpl<TUserDao, TUserEntity, TUserDTO> implements TUserService {

    @Override
    public QueryWrapper<TUserEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<TUserEntity> wrapper = new QueryWrapper<>();

        String phone = (String) params.get("phone");
        String realName = (String) params.get("realName");
        String idCard = (String) params.get("idCard");
        String company = (String) params.get("company");

        if(StringUtils.isNotBlank(phone)){
            wrapper.eq("phone",phone);
        }
        if(StringUtils.isNotBlank(idCard)){
            wrapper.eq("id_card",idCard);
        }
        if(StringUtils.isNotBlank(realName)){
            wrapper.like("real_name",realName);
        }
        if(StringUtils.isNotBlank(company)){
            wrapper.like("company",company);
        }


        return wrapper;
    }

    public TUserEntity getUserByOpenId(String openId) {
        QueryWrapper<TUserEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("openid", openId);
        List<TUserEntity> list = baseDao.selectList(wrapper);
        if(list.size()>0){
            return list.get(0);
        }
        return null;
    }

    public TUserEntity getUserByIdCard(String idCard) {
        QueryWrapper<TUserEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("id_card", idCard);
        List<TUserEntity> list = baseDao.selectList(wrapper);
        if(list.size()>0){
            return list.get(0);
        }
        return null;
    }

}